﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using xs=XmlSearchClass;

namespace ReadConfigNamespace
{
    public class ReadConfig
    {

        public static void writeConfigServer(string strFileName,string strSeverName)
        {
            XmlDocument xdoc = new XmlDocument();
            xdoc.Load(strFileName);

            List<XmlNode> lstNodes =  xs.XmlSearchClass.searchByAttribute("name", "Data Source", xdoc);

            if (lstNodes.Count > 0)
            {
                if (lstNodes[0].Attributes != null)
                    if (lstNodes[0].Attributes["value"] != null)
                    {
                        lstNodes[0].Attributes["value"].Value = strSeverName;
                        xdoc.Save(strFileName);
                    }
            }

        }


        public static void writeServiceConfigServer(string strFileName, string strSeverName)
        {
            XmlDocument xdoc = new XmlDocument();
            xdoc.Load(strFileName);

            List<XmlNode> lstNodes = xs.XmlSearchClass.searchByAttribute("key", "conn", xdoc);

            if (lstNodes.Count > 0)
            {
                if (lstNodes[0].Attributes != null)
                    if (lstNodes[0].Attributes["value"] != null)
                    {
                        string strConn = lstNodes[0].Attributes["value"].Value;
                        strConn = strConn.Replace("__ServerName__", strSeverName);

                        lstNodes[0].Attributes["value"].Value = strConn;
                        xdoc.Save(strFileName);
                    }
            }

        }

    }
}
